<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@page import="utility.connections"%>
<%! 
	String matricola="",username,passwd,email,datareg,tipologia;
%>
<%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			matricola=request.getParameter("matricola");
			}
			
%>
<script type="text/javascript" src="../../js/checkdate.js"></script>
<script type="text/javascript">
	function insert(formName)
	{
		var pattern = /\w+@\w+.\w+/;
		var number= /[0-9]/;
		var	user=document.forms[formName].elements["username"].value;
		var passwd=document.forms[formName].elements["password"].value;
		var email=document.forms[formName].elements["email"].value;
		if(document.forms[formName].elements["dataregistrazione"].value.length==0)
		{
			alert("ERROR data registrazione non inserita");
		}
		if(user.length==0)
		{
			alert("ERROR campo user name non vuoto");
			return;
		}
		if(passwd.length<8)
		{
			alert("ERROR lunghezza password inserita non sufficente");
			return;
		}
		if(!pattern.test(email))
		{	
			alert("ERROR forma campo E-mail errato");
			return;
		}
		document.forms[formName].submit();	
	}
	function isEqual(string1, string2)
	{
		string1=string1.toUpperCase();
		string2=string2.toUpperCase();
		if(string1.indexOf(string2,0)<0)
			{return false;}
		else
			{return true;}
	}
	function chkData(value)
	{
		var early;
		
		if (isEqual(value,"dataregistrazione"))
		{
			if(!isDate(document.form1.dataregistrazione.value))
			{
				alert("Data non valida");
				document.form1.dataregistrazione.value="";
				document.form1.dataregistrazione.focus();
				return;
			}
			document.form1.tipologia.focus();
		}
	}
	function insData(value)
	{		
		var dat;
		var obj;
		var nxt;
		
		if(isEqual(value,"dataregistrazione"))
		{
			dat = document.form1.dataregistrazione.value;
			obj = document.form1.dataregistrazione;
			nxt = document.form1.tipologia;
		}
		
		if(dat.length==2||dat.length==5)
		{
			dat = dat + "/";
			obj.value=dat;
		}
		else if(dat.length==10)
		{
			obj.blur();
		}
	}
	function back()
	{
		document.form1.action="../hadm.jsp";
		document.form1.submit();	
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>nuovo account</title>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="js/immagini.js"></script>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td colspan="4" align="center"></td>
        </tr>
      <tr>
        <td colspan="4" class="style3"><p align="center"><strong>Inserisci i dati del dipendente  </strong></p></td>
        </tr>
        <tr>
	  <form name="form1" method="post" action="../../insert_account">
	  </td>
	  <tr>
        <td class="style3">&nbsp;</td>
        <td class="style3"><div align="right">username:</div></td>
        <td class="style3"><input type="text" name="username" value="" /></td>
        <td class="style3">&nbsp;</td>
      </tr>
      <tr>
        <td class="style3">&nbsp;</td>
        <td class="style3"><div align="right">password: </div></td>
        <td class="style3"><input type="text" name="password" value="" /></td>
        <td class="style3">&nbsp;</td>
      </tr>
      <tr>
        <td class="style3">&nbsp;</td>
        <td class="style3"><div align="right">email:</div></td>
        <td class="style3"><input type="text" name="email" value="" /></td>
        <td class="style3">&nbsp;</td>
      </tr>
       <tr>
         <td class="style3">&nbsp;</td>
         <td class="style3"><div align="right">data registrazione:</div></td>
         <td class="style3"><input type="text" name="dataregistrazione" onblur="javascript:chkData('dataregistrazione');" onKeyUp="javascript:insData('dataregistrazione')" ></input></td>
         <td class="style3">&nbsp;</td>
       </tr>
       <tr>
        <td width="16%" class="style3">&nbsp;</td>
        <td width="20%" class="style3"><div align="right">tipologia:</div></td>
        <td width="39%" class="style3"><div align="left"><label>
       		<select name="tipologia">
      		<option>1,Amministratore</option>
        	<option>2,Addetto Amministrativo</option>
        	<option>3,Dipendente</option>
       		</select>
      		</label></div></td>
        <td width="25%" class="style1">&nbsp;</td>
      </tr>
      <tr>
        <td class="style3">&nbsp;</td>
        <td class="style3"><div align="right">matricola:</div></td>
        <td class="style3"><input type="text" name="matricola" value=<%=matricola%> readonly="readonly"/></td>
        <td class="style3">&nbsp;</td>
      </tr>
      <tr>
        <td class="style1">&nbsp;</td>
        <td class="style1">&nbsp;</td>
        <td class="style1">
    <input type="button" value="INDIETRO"  onclick="javascript:back();"/>
    <input type="button" value="INSERISCI" onclick="javascript:insert('form1');"/>
	<input type="text" name="data" value="" style="visibility:hidden;"/>
	</form>  
	
					      
    </table></td>
  </tr>
  <tr>
    <td align="center" valign="middle">
    <%
    	String qry = "select count(*) as totale from personale";
    	ResultSet rs = connections.getStatement().executeQuery(qry);
    	rs.next();
    	out.println("TOTALE RECORD: " + rs.getString("totale"));
    	
    	rs.close();
    %>
    </td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#000099"><div align="right" class="style4">NUOVO DIPENDENTE</div></td>
  </tr>
</table>
</body>
</html>
